package com.zxkj.commonpatrol.repoisity;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.SPUtils;
import com.zxkj.commonpatrol.model.entity.DeciveEventEntity;
import com.zxkj.commonpatrol.model.post.PostDevPatrolInfo;
import com.zxkj.commonpatrol.model.post.PostDevQuestPatrolHisoty;
import com.zxkj.commonpatrol.model.response.DevEvtPatrolInfoResponse;
import com.zxkj.commonpatrol.model.response.DevEvtQuestPatrolHistoryResponse;
import com.zxkj.commonpatrol.net.ETFApiHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import okhttp3.ResponseBody;

public class DeciveEventDetailRepoisity extends BaseRepository {
    public DeciveEventDetailRepoisity() {

    }

    //初始化選擇項目列表
    public void getSelectProject(int type, MyBaseDataCallBack<List<DeciveEventEntity>> mDataCallBack) {
        List<DeciveEventEntity> datas = new ArrayList<>();

        if (type == 2) {
            for (int i = 6; i < 19; i++) {
                DeciveEventEntity eventEntity = new DeciveEventEntity();
                if (i % 2 == 0) {
                    eventEntity.setStatus(0);
                } else {
                    eventEntity.setStatus(1);
                }
                eventEntity.setTitle("滅火器狀態是否良好" + i);
                eventEntity.setTv_ex1(1 + "滅火器狀態良好");
                eventEntity.setTv_ex2(2 + "滅火器狀態良好");
                eventEntity.setTv_name("NIKO");
                eventEntity.setTv_time("2020/09/01");
                datas.add(eventEntity);
            }
        } else if (type == 1) {
            for (int i = 6; i < 19; i++) {
                DeciveEventEntity eventEntity = new DeciveEventEntity();

                eventEntity.setStatus(1);

                eventEntity.setTitle("滅火器狀態是否良好" + i);
                eventEntity.setTv_ex1(1 + "滅火器狀態良好");
                eventEntity.setTv_ex2(2 + "滅火器狀態良好");
                eventEntity.setTv_name("NIKO");
                eventEntity.setTv_time("2020/09/01");
                datas.add(eventEntity);
            }
        } else {
            for (int i = 6; i < 19; i++) {
                DeciveEventEntity eventEntity = new DeciveEventEntity();

                eventEntity.setStatus(0);

                eventEntity.setTitle("滅火器狀態是否良好" + i);
                eventEntity.setTv_ex1(1 + "滅火器狀態良好");
                eventEntity.setTv_ex2(2 + "滅火器狀態良好");
                eventEntity.setTv_name("NIKO");
                eventEntity.setTv_time("2020/09/01");
                datas.add(eventEntity);
            }
        }

        mDataCallBack.onDataSuccessCallBack(datas);

    }
/**
 *desc:DeviceNo  设备和事件
 *author:mid
 *addtime:2020/7/11 14:41
            *
            */
    public void getDevPatrolInfo(String routeInspectNo, String PointNo, String DeviceNo, String QuestsNo, String Filter, int Categoryid,int Type, MyBaseDataCallBack myBaseDataCallBack) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID, ""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN, ""));
        map.put("Lang", 1);

        PostDevPatrolInfo postDevPatrolInfo = new PostDevPatrolInfo();
        postDevPatrolInfo.setCategoryid(Categoryid);
        postDevPatrolInfo.setDevEvtNo(DeviceNo);
        postDevPatrolInfo.setFilter(Filter);
        postDevPatrolInfo.setPointNo(PointNo);
        postDevPatrolInfo.setQuestsNo(QuestsNo);
        postDevPatrolInfo.setRouteInspectNo(routeInspectNo);
        postDevPatrolInfo.setDevEvtType(Type);

        ETFApiHelper.geRadomApi().getDevPatrolInfo(map, new BaseHttpUtil<PostDevPatrolInfo>().convertVo2Json(postDevPatrolInfo))
                .compose(Transformer.switchSchedulers())
                .subscribe(new CommonObserver<DevEvtPatrolInfoResponse>() {
                    @Override
                    protected void onError(String errorMsg) {
                        myBaseDataCallBack.onDataFailCallBack(404, errorMsg);
                    }

                    @Override
                    protected void onSuccess(DevEvtPatrolInfoResponse devEvtPatrolInfoResponse) {
                        myBaseDataCallBack.onDataSuccessCallBack(devEvtPatrolInfoResponse);
                    }
                });
    }

}
